package com.qire.manhua.controller;

import android.view.View;

import com.qire.antsrouter.AntsRouter;
import com.qire.antsrouter.card.FloorCard;
import com.qire.common.basic.ObjectUtil;
import com.qire.common.constant.Navigation;
import com.qire.manhua.BR;
import com.qire.manhua.activity.helper.LoginRouter;
import com.qire.manhua.databinding.FragmentRecommendVipZoneBinding;
import com.qire.manhua.fragment.RecommendVipZoneFragment;
import com.qire.manhua.model.enumeration.VipPrivilegeType;
import com.qire.manhua.model.viewModel.impl.RecommendVipZoneViewModel;
import com.qire.manhua.model.viewModel.impl.RecommendVipZoneViewModel.VipBannerItemViewModel;

import androidx.annotation.NonNull;
import androidx.annotation.Px;
import androidx.databinding.ViewDataBinding;

public class RecommendVipZoneController extends RecommendModuleController<RecommendVipZoneFragment> implements RecommendModuleRecordController {

    private RecommendVipZoneViewModel viewModel;

    public RecommendVipZoneController(@NonNull RecommendVipZoneFragment lifecycleOwner) {
        super(lifecycleOwner);
    }

    @Override
    protected void bindView() {
        FragmentRecommendVipZoneBinding viewDataBinder = owner.viewDataBinder();
        if(viewDataBinder != null) {
            viewDataBinder.setRecommendVipZoneController(this);
        }
    }

    @Override
    public void bindVariable(ViewDataBinding viewBind) {
        super.bindVariable(viewBind);
        viewBind.setVariable(BR.recommendVipZoneController, this);
        viewBind.setVariable(BR.recommendModuleRecordController, this);
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        this.viewModel = null;
    }

    public void onAddition(RecommendVipZoneViewModel viewModel) {
        this.viewModel = viewModel;
    }

    /*************************************************************************************************************************/

    public void bannerOnPageScrolled(int position, float positionOffset, @Px int positionOffsetPixels) {
        //        boolean isLeft = positionOffset;
        if(positionOffsetPixels == 0 && ObjectUtil.nonNull(viewModel)) {
            viewModel.changeBannerBackground(position);
        }
    }
    public void bannerOnPageSelected(int position) {
        if(ObjectUtil.nonNull(viewModel)) {
            viewModel.changeBannerBackground(position);
        }
    }
    
    /**
     * 点击banner广告
     * @param view
     */
    public void onBannerItemClick(View view) {
        VipBannerItemViewModel bannerItemViewModel = (VipBannerItemViewModel) view.getTag();
        bannerItemViewModel.doAction();
    }

    public void openVipPageBtnOnClick(View view) {
        VipPrivilegeType type = ObjectUtil.as(view.getTag(), VipPrivilegeType.class);
        if(ObjectUtil.nonNull(type)) {
            AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.VipInstructionsPage)
                    .withData("type", type)
                    .navigation();
        }
    }

    public void loginBtnOnClick(View view){
        LoginRouter.ROUTER.checkLoginRouteIfNeed();
    }

    public void buyMembershipBtnOnClick(View view){
        AntsRouter.ROUTER.buildCard(Navigation.Page.BuyMembershipPage).navigation();
    }

    public void errorReloadBtnOnClick(View view){
        viewModel.loadVipZoneData();
    }

    @Override
    public void moduleRecordMoreBtnOnClick(View view) {
        AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.ComicRankListOfVipPage).navigation();
    }

}
